<?php

namespace App\Console\Commands;

use App\Imports\HospitalImport;
use App\Jobs\SyncDataChild;
use App\Jobs\TempPush;
use App\Models\FamilyEdu;
use App\Models\Hospital;
use App\Console\Commands\HospitalAppointInterval;
use App\Models\HospitalAppointIntervalNum;
use App\Models\FamilyType;
use App\Models\HospitalImportChild;
use App\Models\HospitalUploadData;
use App\Models\old\HospitalAppoint;
use App\Models\old\HospitalAppointStreet;
use App\Models\old\HospitalAppointVaccineTimeNum;
use App\Models\old\HospitalAppointWeek;
use App\Models\old\OldHospital;
use App\Models\old\OldHospitals;
use App\Models\old\Street;
use App\Models\TempPushRecord;
use App\Models\Vaccine;
use App\Models\VaccineType;
use Illuminate\Console\Command;
use Illuminate\Support\Facades\DB;
use Maatwebsite\Excel\Facades\Excel;
use OSS\Credentials\EnvironmentVariableCredentialsProvider;
use OSS\OssClient;
use App\Exceptions\Arr;
use Illuminate\Support\Facades\Http;

class Contrast extends Command
{
    /**
     * The name and signature of the console command.
     *
     * @var string
     */
    protected $signature = 'contrast';

    /**
     * The console command description.
     *
     * @var string
     */
    protected $description = 'Command description';

    /**
     * Create a new command instance.
     *
     * @return void
     */
    public function __construct()
    {
        parent::__construct();
    }

    /**
     * Execute the console command.
     *
     * @return int
     */
    public function handle()
    {
//        $hospitals = OldHospital::query()->get();
//        foreach ($hospitals as $hospital) {
//            $oldResponse = Http::get('http://www.erbb.com/v4/appoint/doctor?id='.$hospital->userid);
//            $oldData = $oldResponse->json();
//            $types = Arr::get($oldData, 'data.types');
//            if(!$types) {
//                $types=[];
//            }
//            $typesArr = array_filter($types, function ($where) {
//                return $where['is_type'] == 1;
//            });
//            $names = Arr::pluck($typesArr, 'name');
//            array_unshift($names,$hospital->name);
//            echo "old,";
//            echo implode(',',$names);
//            echo "\n";
//
//
//            $newResponse = Http::withOptions([
//                'verify' => false, // 关闭 SSL 验证
//            ])->get('https://ebbapi.binglang6.com/new/ebb/hospital/getHospitalProject/'.$hospital->userid);
//            $newData = $newResponse->json();
//            $names = Arr::pluck($newData['data'], 'name');
//            array_unshift($names,$hospital->name);
//            echo "new,";
//            echo implode(',',$names);
//            echo "\n";
//        }
//        $hospitals = OldHospital::query()->get();
//        foreach ($hospitals as $hospital){
//            $oldResponse = Http::get('http://www.erbb.com/v4/appoint/form',['id'=>$hospital->userid,'type'=>1]);
//            $oldData = $oldResponse->json();
//            $types = Arr::get($oldData, 'data.monthType');
//            if(!$types) {
//                $types=[];
//            }
//            $names = Arr::pluck($types, 'text');
//            if(!$types) {
//                array_unshift($names,'社区医院暂未开通服务！');
//            }
//            array_unshift($names,$hospital->name);
//
//            echo "old,";
//            echo implode(',',$names);
//
//            echo "\n";
//            $newResponse = Http::withOptions([
//                'verify' => false, // 关闭 SSL 验证
//            ])->get('https://ebbapi.binglang6.com/new/ebb/hospital/getHospitalChildExamine/'.$hospital->userid);
//            $newData = $newResponse->json();
//            $names = Arr::pluck($newData['data'], 'type_name');
//            array_unshift($names,$hospital->name);
//            echo "new,";
//            echo implode(',',$names);
//            echo "\n";
//        }

        $hospitals = OldHospital::query()->get();
        foreach ($hospitals as $hospital){
//            $oldResponse = Http::get('http://www.erbb.com/v4/appoint/form',['id'=>$hospital->userid,'type'=>1]);
//            $oldData = $oldResponse->json();
//            $types = Arr::get($oldData, 'data.monthType');
//            if(!$types) {
//                $types=[];
//            }
//            $names = Arr::pluck($types, 'text');
//            if(!$types) {
//                array_unshift($names,'社区医院暂未开通服务！');
//            }
//            array_unshift($names,$hospital->name);
//
//            echo "old,";
//            echo implode(',',$names);

            echo "\n";
            $newResponse = Http::withOptions([
                'verify' => false, // 关闭 SSL 验证
            ])->post('https://ebbapi.binglang6.com/new/ebb/hospital/getAppointStree');
            $newData = $newResponse->json();
            //$names = Arr::pluck($newData['data'], 'childrenFreeVaccine');
            $vaccines = $newData['data']['childrenFreeVaccine'];
            if(!$vaccines){
                $vaccines = [];
            }
            foreach($vaccines as $vaccine){

            }
            $names = Arr::pluck($vaccines, 'name');

            array_unshift($names,$hospital->name);
            echo "new,";
            echo implode(',',$names);
            echo "\n";
        }

        return 0;
    }
}
